const config = require('../config/config')

const Wechat = require('../wechat-lib/Iindex')
const mongoose = require ('mongoose')

const Token = mongoose.model('Token')

const wechatCfg = {
    wechat: {
        appID: config.wehchat.appID,
        appSecret: config.wehchat.appSecret,
        token: config.wehchat.token,
        getAccessToken: async () => {
            const res = await Token.getAccessToken()
            return res

        },
        saveAccessToken: async (data) => {
            const res = await Token.saveAccessToken(data)
            return res

        }
    }
}



exports.test = async () => {
    const client = new Wechat(wechatCfg.wechat)

    const data = await client.fetchAccessToken()
    console.log('data in db ')
    console.log(data)
}

